#!/bin/env python3
# -*- coding:utf-8 -*-
"""
    [模块名]
    Add By : cdj <e4ting@qq.com> 2021-07-14 17:57:18
"""
from flask_restful import Resource
from flask         import redirect,request,make_response
from e4ting        import log
# from poker import rooms,player

class TexasRoom(Resource):
    """游戏房间"""
    # def __init__(self):
    #     super(TexasRoom, self).__init__()

    def get(self, name=None):
        log.info("info = ", self.info)
        enable = request.args.get("enable", None)
        if enable is None:
            data = rooms.get_rooms()
        else:
            data = rooms.get_rooms(enable=bool(enable))
        return {
            "code" : 200,
            "data"  : data,
        }

    def post(self, name=None):
        """创建房间"""

        log.info("info = ", self.info)
        ip = request.headers["X-Real-Ip"]
        room_id = rooms.creat_room(name, ip=ip, author=self.info["name"])
        data = rooms.get_rooms(_id=room_id)[0]
        return {
            "code" : 200,
            "data"  : data,
        }

